package com.edu.exam.enums.curriculum;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 权限类型枚举
 *
 * @author System
 * @version 1.0.0
 */
public enum PermissionType implements BaseEnum {
    VIEW("VIEW", "查看"),
    DOWNLOAD("DOWNLOAD", "下载"),
    EDIT("EDIT", "编辑"),
    DELETE("DELETE", "删除"),
    SHARE("SHARE", "分享"),
    MANAGE("MANAGE", "管理"),
    APPROVE("APPROVE", "审批"),
    FULL_ACCESS("FULL_ACCESS", "完全访问");

    private final String code;
    private final String description;

    PermissionType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    public static PermissionType fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("PermissionType code cannot be null or empty");
        }
        for (PermissionType type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown PermissionType code: " + code);
    }

    public static PermissionType fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            throw new IllegalArgumentException("PermissionType description cannot be null or empty");
        }
        for (PermissionType type : values()) {
            if (type.getDescription().equals(description)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown PermissionType description: " + description);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}